package leetcode_301_400;

import java.util.Arrays;

public class LeeCode_324 {
    public static void main(String[] args) {
        wiggleSort(new int[]{1,5,1,1,6,4});
        wiggleSort(new int[]{1,2,3,4,5,6,7});
        wiggleSort(new int[]{4,5,5,6});
    }
    private static void wiggleSort(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length;
        int[] ans = new int[n];
        int l = (n - 1) / 2;
        int t = l;
        int r = n - 1;
        int i = 0;
        while (r > t){
            ans[i++] = nums[l--];
            ans[i++] = nums[r--];
        }
        if (n % 2 == 1){
            ans[i] = nums[l];
        }
        System.arraycopy(ans, 0, nums, 0, n);
        System.out.println(Arrays.toString(nums));
    }
}
